package com.ssy.jt808.gateway.infrastructure.config;

import com.ssy.jt808.gateway.domain.property.KafkaConfigProperties;
import com.ssy.jt808.gateway.sdk.terminal.constant.MessageTopicConstant;
import org.apache.kafka.clients.admin.NewTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author wangzezhou
 */
@Configuration
public class TerminalMessageConfig{
  @Bean
  public NewTopic locationInfoTopic( KafkaConfigProperties properties ){
    KafkaConfigProperties.TopicSetting topic = properties.getTopic();
    NewTopic newTopic = new NewTopic(MessageTopicConstant.LOCATION_INFO, topic.getPartitions(), topic.getReplicas());
    newTopic.configs(topic.getConfig());
    return newTopic;
  }

  @Bean
  public NewTopic connectionStatusTopic( KafkaConfigProperties properties ){
    KafkaConfigProperties.TopicSetting topic = properties.getTopic();
    NewTopic newTopic = new NewTopic(MessageTopicConstant.CONNECTION_STATUS,
                                     topic.getPartitions(),
                                     topic.getReplicas());
    newTopic.configs(topic.getConfig());
    return newTopic;
  }

  @Bean
  public NewTopic alarmInfoTopic( KafkaConfigProperties properties ){
    KafkaConfigProperties.TopicSetting topic = properties.getTopic();
    NewTopic newTopic = new NewTopic(MessageTopicConstant.ALARM_INFO, topic.getPartitions(), topic.getReplicas());
    newTopic.configs(topic.getConfig());
    return newTopic;
  }
}
